<template>
  <div class="app-container calendar-list-container maintenance">
    <div class="apply-query">
      <el-row class="filter-query">
        <el-col><span>{{$t('specialApplication.maintenance.queryCondition')}}</span></el-col> <!--查询条件-->
      </el-row>
      <popover-set-query @clickShow="clickShow">
        <el-form :inline="true" :model="listQuery" style="padding: 0 20px" :class="{'show':!showI}">
          <el-row style="padding-bottom: 10px">
            <!-- 標前會議日期 -->
            <el-col :span="4">
              <div class="w20">
                <div class="labelName">{{$t('specialApplication.maintenance.isValue')+
                '('+$t('specialApplication.maintenance.bidBeforeMeetingDate')+')'}}</div>
                <el-select v-model="listQuery.isBidBeforeValue" :clearable="true" :placeholder="$t('placeholder.choose')" @change="isBidBeforeMeetingDateValue" >
                  <el-option
                    v-for="item in isValues" :key="item.value" :label="item.label" :value="item.value">
                  </el-option>
                </el-select>
              </div>
            </el-col>
            <el-col :span="4">
              <div class="w20">
                <div class="labelName">{{$t('specialApplication.maintenance.bidBeforeMeetingDate')}}</div>
                <el-date-picker style="width: 100%" format="yyyy-MM-dd" value-format="yyyy-MM-dd" v-model="listQuery.bidBeforeMeetingDate" :disabled="dateDisabled1"
                                type="daterange" range-separator="-" :start-placeholder="$t('placeholder.startDate')" :end-placeholder="$t('placeholder.endDate')"></el-date-picker> <!--开始日期--><!--结束日期-->
              </div>
            </el-col>
            <!-- 内部啓動會議日期-->
            <el-col :span="4">
              <div class="w20">
                <div class="labelName">{{$t('specialApplication.maintenance.isValue')+
                '('+$t('specialApplication.maintenance.innerStartMeetingDate')+')'}}</div>
                <el-select v-model="listQuery.isInnerStartValue" :clearable="true" :placeholder="$t('placeholder.choose')" @change="isInnerStartMeetingDateValue" >
                  <el-option
                    v-for="item in isValues" :key="item.value" :label="item.label" :value="item.value">
                  </el-option>
                </el-select>
              </div>
            </el-col>
            <el-col :span="4">
              <div class="w20">
                <div class="labelName">{{$t('specialApplication.maintenance.innerStartMeetingDate')}}</div>
                <el-date-picker style="width: 100%" format="yyyy-MM-dd" value-format="yyyy-MM-dd" v-model="listQuery.innerStartMeetingDate" :disabled="dateDisabled2"
                                type="daterange" range-separator="-" :start-placeholder="$t('placeholder.startDate')" :end-placeholder="$t('placeholder.endDate')"></el-date-picker> <!--开始日期--><!--结束日期-->
              </div>
            </el-col>
            <!-- 外部啓動會議日期 -->
            <el-col :span="4">
              <div class="w20">
                <div class="labelName">{{$t('specialApplication.maintenance.isValue')+
                '('+$t('specialApplication.maintenance.outerStartMeetingDate')+')'}}</div>
                <el-select v-model="listQuery.isOuterStartValue" :clearable="true" :placeholder="$t('placeholder.choose')" @change="isOuterStartMeetingDateValue" >
                  <el-option
                    v-for="item in isValues" :key="item.value" :label="item.label" :value="item.value">
                  </el-option>
                </el-select>
              </div>
            </el-col>
            <el-col :span="4">
              <div class="w20">
                <div class="labelName">{{$t('specialApplication.maintenance.outerStartMeetingDate')}}</div>
                <el-date-picker style="width: 100%" format="yyyy-MM-dd" value-format="yyyy-MM-dd" v-model="listQuery.outerStartMeetingDate" :disabled="dateDisabled3"
                                type="daterange" range-separator="-" :start-placeholder="$t('placeholder.startDate')" :end-placeholder="$t('placeholder.endDate')"></el-date-picker> <!--开始日期--><!--结束日期-->
              </div>
            </el-col>

            <el-col :span="4">
              <div class="w20">
                <div class="labelName">{{$t('specialApplication.maintenance.country')}}</div>
                <dict-select v-model="listQuery.country" code="country" :clearable="true" @change="setBg"></dict-select>
              </div>
            </el-col>
            <el-col :span="4">
              <div class="w20">
                <div class="labelName">Category</div>
                <el-select multiple collapse-tags filterable  v-model="listQuery.bg" @change="changeBg" :placeholder="$t('placeholder.choose')">
                  <el-option v-for="item in bgList" :key="item" :label="item" :value="item">
                  </el-option>
                </el-select>
              </div>
            </el-col>

            <el-col :span="4">
              <div class="w20">
                <div class="labelName">Account</div>
                <el-select multiple collapse-tags filterable clearable v-model="bu"  :placeholder="$t('placeholder.choose')">
                  <el-option v-for="item in buList" :key="item" :label="item" :value="item"></el-option>
                </el-select>
              </div>
            </el-col>
            <el-col :span="4">
              <div class="w20">
                <div class="labelName">BD Name</div><!--请输入名称-->
                <el-input v-model="listQuery.bdName" :placeholder="$t('placeholder.name')" clearable class="filter-item"></el-input>
              </div>
            </el-col>
            <el-col :span="4">
              <div class="w20">
                <div class="labelName">Start Date</div>
                <el-date-picker style="width: 100%" format="yyyy-MM-dd" value-format="yyyy-MM-dd" v-model="listQuery.startDate" type="daterange" range-separator="-" :start-placeholder="$t('placeholder.startDate')" :end-placeholder="$t('placeholder.endDate')"></el-date-picker> <!--开始日期--><!--结束日期-->
              </div>
            </el-col>
            <el-col :span="4">
              <div class="w20">
                <div class="labelName">Status</div>
                <el-select clearable multiple class="yt-multiple" v-model="listQuery.status" :placeholder="$t('placeholder.choose')">
                  <el-option v-for="item in demandStatusList" :key="item.label" :label="item.label" :value="item.label"></el-option>
                </el-select>
              </div>
            </el-col>
            <el-col :span="4">
              <div class="w20">
                <div class="labelName">Sales/Presales/PM</div>
                <!-- <el-input v-model="listQuery.user" :placeholder="$t('placeholder.enterNoOrName')" clearable class="filter-item"></el-input> -->
                <popover-select selectType="user" :placeholder="$t('placeholder.enterNoOrName')" valueObjName="ename" v-model="listQuery.user"></popover-select>
                <!--請輸入員編/姓名-->
              </div>
            </el-col>
            <el-col :span="4">
              <div class="w20">
                <div class="labelName">Client</div>
                <!-- <el-autocomplete style="width: 100%" clearable v-model="listQuery.clientName" :fetch-suggestions="getCustomerList" :placeholder="$t('placeholder.enterShortOrAllName')" @select="selectCustomer"></el-autocomplete> -->
                <!--请输入简称或全称-->
                <popover-select @setValue="selectCustomer" selectType="customer" :placeholder="$t('placeholder.enterShortOrAllName')" valueObjName="customerShortName" v-model="listQuery.clientName"></popover-select>
              </div>
            </el-col>
            <el-col :span="4">
              <div class="w20">
                <div class="labelName">財務模式</div>
                <dict-select v-model="listQuery.clientType" code="clientType" :clearable="true"></dict-select>
              </div>
            </el-col>
            <el-col :span="4">
              <div class="w20">
                <div class="labelName">Target Quarter</div>
                <yt-time-quarter style="width: 100%" :targetQuarterDate.sync="listQuery.targetQuarterDate" :placeholder="$t('specialApplication.maintenance.targetQuarterDate')" v-model="listQuery.targetQuarter"></yt-time-quarter>
              </div>
            </el-col>

         

             <el-col :span="6">
              <div class="w20">
                <div class="labelName">Target Date</div>
                  <el-date-picker v-model="listQuery.targetDateStart" style="width: 45%" type="date" value-format="yyyy-MM-dd" format="yyyy-MM-dd" :placeholder="$t('placeholder.choose')"/>
                  <span>-</span>
                  <el-date-picker v-model="listQuery.targetDateEnd" style="width: 45%;display: inline-block" type="date" value-format="yyyy-MM-dd" format="yyyy-MM-dd" :placeholder="$t('placeholder.choose')"/>
              </div>
            </el-col>

      
            <el-col :span="4">
              <div class="w20">
                <div class="labelName">董事會列管年度</div>
                <el-date-picker v-model="listQuery.directorDate" type="year" value-format="yyyy" format="yyyy" :placeholder="$t('placeholder.choose')"/>
              </div>
            </el-col>


       
            <el-col :span="6">
              <div class="w20">
                <div class="labelName">預計簽約日</div>
                  <el-date-picker v-model="listQuery.targetMonthStart" style="width: 45%" type="month" value-format="yyyy-MM" format="yyyy-MM" :placeholder="$t('placeholder.choose')"/>
                  <span>-</span>
                  <el-date-picker v-model="listQuery.targetMonthEnd" style="width: 45%;display: inline-block" type="month" value-format="yyyy-MM" format="yyyy-MM" :placeholder="$t('placeholder.choose')"/>
              </div>
            </el-col>
         

           
            <el-col :span="6">
              <div class="w20">
                <div class="labelName">Estimated Revenue</div>
                <el-input style="width: 125px" @blur="inputMoney($event,'estimatedBudgetMinString')" :clearable="true" v-model="listQuery.estimatedBudgetMinString" :placeholder="$t('placeholder.content')"></el-input>
                <span>-</span>
                <el-input style="width: 125px"  @blur="inputMoney($event,'estimatedBudgetMaxString')" :clearable="true" v-model="listQuery.estimatedBudgetMaxString" :placeholder="$t('placeholder.content')"></el-input>
              </div>
            </el-col>

         
           
          
            <el-col :span="4" style="margin-top: 32px">
              <div type="primary" class="yt-btn yt-btn-ys" @click="handleFilter">{{$t('button.search')}}</div>
              <div type="primary" class="yt-btn yt-ml8" @click="reset">{{$t('button.reset')}}</div>
            </el-col>
          </el-row>
        </el-form>
      </popover-set-query>
    </div>

    <div class="yt-data-list">
      <div class="yt-list-title">
        <span>{{$t('specialApplication.maintenance.demand')}}</span><!--商机维护-->
      </div>
      <div class="yt-list-content">
        <div class="list-operation">
          <!--新增-->
          <div class="yt-btn yt-btn-ys" type="primary" @click="newly">{{$t('button.new')}}</div>
          <!--编辑-->
          <!-- <div class="yt-btn yt-ml8" type="primary" @click="handlePreserve('edit')">编辑</div> -->
          <!--删除-->
          <div class="yt-btn yt-ml8" type="danger" v-if="demandDeltePermision" @click="handleDelete('del')">{{$t('button.delete')}}</div>
          <!--专编申请-->
          <div class="yt-btn yt-ml8" type="primary" @click="handlePreserve('application')">{{$t('specialApplication.maintenance.projectApply')}}</div><!--专编申请-->
          <!--业务报价-->
          <div class="yt-btn yt-ml8" type="primary" @click="getMyQuotes">{{$t('specialApplication.maintenance.businessOffer')}}</div><!--业务报价-->
          <!--月份及季别检测-->
          <div class="yt-btn yt-ml8" type="primary" @click="targetCheck">{{$t('specialApplication.maintenance.check')}}</div><!--月份及季别检测-->
          <!--汇出-->
          <div class="yt-btn yt-ml8" type="primary" @click="exportExcel">{{$t('button.export')}}</div><!--汇出-->
          <!--设置栏位-->
          <div class="yt-btn yt-ml8" type="primary" @click="setUp">{{$t('button.sets')}}</div>
        </div>
        <el-table class="yt-table" ref="dataTable" :key="tableKey" :data="list" border highlight-current-row @row-click="clickRow" max-height="600" @selection-change="handleSelectionChange" @sort-change="sortDate">
          <el-table-column align="center" label="Sum">
            <el-table-column align="center" type="selection" prop="id" width="60"/>
          </el-table-column>

          <el-table-column v-if="displayBlockNameStr['countryName']" align="center" label="">
            <el-table-column align="center" :label="$t('specialApplication.maintenance.country')"  prop="countryName" sortable min-width="100"/><!--国别-->
          </el-table-column>
          <el-table-column v-if="displayBlockNameStr['BG']" align="center" label="">
            <el-table-column align="center" label="Category" prop="bg" min-width="100" sortable/>
          </el-table-column>
          <el-table-column v-if="displayBlockNameStr['BU']" align="center" label="">
            <el-table-column align="center" label="Account" prop="bu" min-width="100" sortable/>
          </el-table-column>
          <el-table-column v-if="displayBlockNameStr['clientTypeName']" align="center" label="">
            <el-table-column align="center" label="財務模式" prop="clientTypeName" min-width="100" sortable/>
          </el-table-column>
          <el-table-column  v-if="displayBlockNameStr['territory']"  align="center" label="">
            <el-table-column align="center" label="Territory" prop="territory" min-width="100" sortable/>
          </el-table-column>
          <el-table-column v-if="displayBlockNameStr['clientName']" align="center" label="">
            <el-table-column align="center" label="Client" prop="clientName" min-width="150" sortable :show-overflow-tooltip="true"/>
          </el-table-column>

          <el-table-column v-if="displayBlockNameStr['sales']" align="center" label="">
            <el-table-column align="center" label="Sales" prop="sales" min-width="100" sortable/>
          </el-table-column>

          <el-table-column v-if="displayBlockNameStr['bdValue']" align="center" label="">
            <el-table-column align="center" label="BD No." prop="bdValue" min-width="100" sortable/>
          </el-table-column>
          <el-table-column v-if="displayBlockNameStr['bdName']" align="center" label="">
            <el-table-column align="center" label="BD Name" prop="bdName" min-width="200" sortable :show-overflow-tooltip="true"/>
          </el-table-column>
          <el-table-column v-if="displayBlockNameStr['contactWindowF']" align="center" label="">
            <el-table-column align="center" label="Contact window" prop="contactWindowF" min-width="100" sortable/>
          </el-table-column>
          <el-table-column v-if="displayBlockNameStr['decisionMakerF']" align="center" label="">
            <el-table-column align="center" label="Decision maker" prop="decisionMakerF" min-width="100" sortable/>
          </el-table-column>
          <el-table-column align="center" v-if="displayBlockNameStr['startDate']" :label="subtotal.startDate + ''">
            <el-table-column align="center" label="Start Date" prop="startDate" min-width="100" sortable/>
          </el-table-column>
          <el-table-column align="center" v-if="displayBlockNameStr['forecastMonth']" :label="subtotal.forecastMonth + ''">
            <el-table-column align="center" label="預計報價日" prop="forecastMonth" min-width="100" sortable/>
          </el-table-column>
          
          <el-table-column v-if="displayBlockNameStr['task']" align="center" label="">
            <el-table-column align="center" label="Task" prop="task" min-width="200" sortable :show-overflow-tooltip="true"/>
          </el-table-column>
          <el-table-column align="center" v-if="displayBlockNameStr['targetDate']" :label="subtotal.targetDate + ''">
            <el-table-column align="center" label="Target Date" prop="targetDate" min-width="100" sortable/>
          </el-table-column>

          <el-table-column align="center" v-if="displayBlockNameStr['proposalDate']" :label="subtotal.proposalDate + ''">
            <el-table-column align="center" label="實際報價日" prop="proposalDate" min-width="100" sortable/>
          </el-table-column>
          <el-table-column align="center" v-if="displayBlockNameStr['targetQuarter']" :label="subtotal.targetQuarter + ''">
            <el-table-column align="center" label="Target Quarter" prop="targetQuarter" min-width="100" sortable/>
          </el-table-column>

          <el-table-column align="center" v-if="displayBlockNameStr['targetMonth']" :label="subtotal.targetMonth + ''">
            <el-table-column align="center" label="預計簽約日" prop="targetMonth" min-width="100" sortable/>
          </el-table-column>
          <el-table-column v-if="displayBlockNameStr['presales']" align="center" label="">
            <el-table-column align="center" label="Presales" prop="presales" min-width="100" sortable/>
          </el-table-column>
          <el-table-column v-if="displayBlockNameStr['pm']" align="center" label="">
            <el-table-column align="center" label="PM" prop="pm" min-width="100" sortable/>
          </el-table-column>
          <el-table-column align="center" v-if="displayBlockNameStr['directorDate']" label="">
            <el-table-column align="center" label="董事會列管年度" prop="directorDate" min-width="100" sortable/>
          </el-table-column>
          <el-table-column align="center" v-if="displayBlockNameStr['estimatedBudget']" :label="subtotal.estimatedBudget + ''">
            <el-table-column align="center" label="Estimated Revenue"  prop="estimatedBudget" min-width="100" sortable="custom">
              <template slot-scope="scope">
                <div v-format="'#,##0'">{{ scope.row.estimatedBudget }}</div>
              </template>
            </el-table-column>
          </el-table-column>
          <el-table-column align="center" v-if="displayBlockNameStr['estimatedCost']" :label="subtotal.estimatedCost + ''">
            <el-table-column align="center" label="Estimated cost"  prop="estimatedCost" min-width="100" sortable="custom">
              <template slot-scope="scope">
                <div v-format="'#,##0'">{{ scope.row.estimatedCost }}</div>
              </template>
            </el-table-column>
          </el-table-column>

          <el-table-column align="center" v-if="displayBlockNameStr['estimatedRevenueThis']" :label="subtotal.estimatedRevenueThis + ''">
            <el-table-column align="center" label="Estimated Revenue(this year)"  prop="estimatedRevenueThis" min-width="100" sortable="custom">
              <template slot-scope="scope">
                <div v-format="'#,##0'">{{ scope.row.estimatedRevenueThis }}</div>
              </template>
            </el-table-column>
          </el-table-column>
          <el-table-column align="center" v-if="displayBlockNameStr['estimatedCostThis']" :label="subtotal.estimatedCostThis + ''">
            <el-table-column align="center" label="Estimated Cost(this year)"  prop="estimatedCostThis" min-width="100" sortable="custom">
              <template slot-scope="scope">
                <div v-format="'#,##0'">{{ scope.row.estimatedCostThis }}</div>
              </template>
            </el-table-column>
          </el-table-column>

          <el-table-column align="center" v-if="displayBlockNameStr['directorIncome']" :label="subtotal.directorIncome + ''">
            <el-table-column align="center" label="董事會列管收入"  prop="directorIncome" min-width="100" sortable="custom">
              <template slot-scope="scope">
                <div v-format="'#,##0'">{{ scope.row.directorIncome }}</div>
              </template>
            </el-table-column>
          </el-table-column>

          <el-table-column align="center" v-if="displayBlockNameStr['directorCost']" :label="subtotal.directorCost + ''">
            <el-table-column align="center" label="董事會列管成本"  prop="directorCost" min-width="100" sortable="custom">
              <template slot-scope="scope">
                <div v-format="'#,##0'">{{ scope.row.directorCost }}</div>
              </template>
            </el-table-column>
          </el-table-column>
          <el-table-column align="center" v-if="displayBlockNameStr['status']" label="">
            <el-table-column align="center" label="Status" prop="status" min-width="150" sortable/>
          </el-table-column>
          <el-table-column align="center" v-if="displayBlockNameStr['endDate']" :label="subtotal.endDate + ''">
            <el-table-column align="center" label="End Date" prop="endDate" min-width="100" sortable/>
          </el-table-column>

          <el-table-column align="center" v-if="displayBlockNameStr['isFinishValue']" label="">
            <el-table-column align="center" :label="$t('specialApplication.maintenance.isFinishValue')" prop="isFinishValue" min-width="100" sortable/><!--成案否-->
          </el-table-column>

        
          <el-table-column align="center" v-if="displayBlockNameStr['awardDate']" label="">
            <el-table-column align="center" prop="awardDate"
                             :label="$t('specialApplication.businessMeeting.awardDate')"
                             min-width="150" sortable>
            </el-table-column>
          </el-table-column>

          <el-table-column align="center" v-if="displayBlockNameStr['agenda1']" label="">
            <el-table-column align="center" prop="agenda1" :render-header="renderHeader1"
                             :label="$t('specialApplication.businessMeeting.agenda1')" min-width="150" sortable>
            </el-table-column>
          </el-table-column>

          <el-table-column align="center" v-if="displayBlockNameStr['agenda2']" label="">
            <el-table-column align="center" prop="agenda2" :render-header="renderHeader1"
                             :label="$t('specialApplication.businessMeeting.agenda2')" min-width="150" sortable>
            </el-table-column>
          </el-table-column>

          <el-table-column align="center" v-if="displayBlockNameStr['agenda3']" label="">
            <el-table-column align="center" prop="agenda3" :render-header="renderHeader1"
                             :label="$t('specialApplication.businessMeeting.agenda3')" min-width="150" sortable>
            </el-table-column>
          </el-table-column>

          <el-table-column align="center" v-if="displayBlockNameStr['agenda4']" label="">
            <el-table-column align="center" prop="agenda4" :render-header="renderHeader1"
                             :label="$t('specialApplication.businessMeeting.agenda4')" min-width="150" sortable>
            </el-table-column>
          </el-table-column>

          <el-table-column align="center" v-if="displayBlockNameStr['agenda5']" label="">
            <el-table-column align="center" prop="agenda5" :render-header="renderHeader1"
                             :label="$t('specialApplication.businessMeeting.agenda5')" min-width="150" sortable>
            </el-table-column>
          </el-table-column>

          <el-table-column align="center" v-if="displayBlockNameStr['agenda6']" label="">
            <el-table-column align="center" prop="agenda6" :render-header="renderHeader1"
                             :label="$t('specialApplication.businessMeeting.agenda6')" min-width="150" sortable>
            </el-table-column>
          </el-table-column>

          <el-table-column align="center" v-if="displayBlockNameStr['bidBeforeMeetingRemark']" label="">
            <el-table-column align="center" prop="bidBeforeMeetingRemark"
                             :label="$t('specialApplication.businessMeeting.bidBeforeMeetingRemark')"
                             min-width="200" sortable :show-overflow-tooltip="true">
            </el-table-column>
          </el-table-column>

       

       




         
          <el-table-column align="center" v-if="displayBlockNameStr['winOddsName']" label="">
            <el-table-column align="center" label="Win Odds %" prop="winOddsName" sortable="custom" min-width="100">
              <template slot-scope="scope">
                <div>{{ scope.row.winOddsName }}</div>
              </template>
            </el-table-column>
          </el-table-column>
          <el-table-column align="center" v-if="displayBlockNameStr['traceMonth']" label="">
            <el-table-column align="center" prop="traceMonth" label="Tracking Time" min-width="100" sortable/>
          </el-table-column>
          <!--標前會議日期-->
          <el-table-column align="center" v-if="displayBlockNameStr['bidBeforeMeetingDate']" label="">
            <el-table-column align="center" prop="bidBeforeMeetingDate" :label="$t('specialApplication.maintenance.bidBeforeMeetingDate')" min-width="100" sortable/>
          </el-table-column>
          <!--內部啟動會議日期(Award70%)-->
          <el-table-column align="center" v-if="displayBlockNameStr['innerStartMeetingDate']" label="">
            <el-table-column align="center" prop="innerStartMeetingDate" :render-header="renderHeader1"
                             :label="$t('specialApplication.maintenance.innerStartMeetingDate')+' (Award70%)'" min-width="100">
              <template slot-scope="scope">
                <span v-if="scope.row.innerStartMeetingDateIs !== '1'">{{scope.row.innerStartMeetingDate}}</span>
                <span v-else>N/A</span>
              </template>
            </el-table-column>
          </el-table-column>
          <!--外部啟動會議日期(Award70%)-->
          <el-table-column align="center" v-if="displayBlockNameStr['outerStartMeetingDate']" label="">
            <el-table-column align="center"  prop="outerStartMeetingDate" :render-header="renderHeader1"
                             :label="$t('specialApplication.maintenance.outerStartMeetingDate')+' (Award70%)'" min-width="100">
              <template slot-scope="scope">
                <span v-if="scope.row.outerStartMeetingDateIs !== '1'">{{scope.row.outerStartMeetingDate}}</span>
                <span v-else>N/A</span>
              </template>
            </el-table-column>
          </el-table-column>
          <el-table-column align="center" v-if="displayBlockNameStr['actionsSales']" label="">
            <el-table-column align="center" label="進度說明(Sales&Presales)" prop="actionsSales" min-width="100" :show-overflow-tooltip="true" sortable/>
          </el-table-column>
          <el-table-column align="center" v-if="displayBlockNameStr['actionsPresales']" label="">
            <el-table-column align="center" label="進度說明(高階主管)" prop="actionsPresales" min-width="100" :show-overflow-tooltip="true" sortable/>
          </el-table-column>
        
          <el-table-column align="center" v-if="displayBlockNameStr['projectNo']" label="">
            <el-table-column align="center" :label="$t('specialApplication.maintenance.projectNo')" prop="projectNo" min-width="100" sortable/><!--对应专编-->
          </el-table-column>
        </el-table>

        <!--设置可见栏位-->
      <el-dialog :title="$t('projectRevenue.dataReport.setVisible')" :visible.sync="TableTitleVisible">
        <yt-table-title :blockNameCode="blockNameCode" :displayBlockNameList ="displayBlockNameList" @cancel="cancel"></yt-table-title>
      </el-dialog>

        <el-dialog :visible.sync="statusDialogTable" width="50%">
          <el-table :data="dialogList" :empty-text="$t('placeholder.emptyText')" label-width="100px" class="yt-table">
            <el-table-column label="123" align="left" :render-header="renderHeader">
              <template slot-scope="scope">
                <div>{{scope.row.name}}</div>
                <div>{{scope.row.nameText}}</div>
              </template>
            </el-table-column>
            <el-table-column label="Status" prop="status" align="center"/>
            <el-table-column :label="$t('specialApplication.maintenance.winOdd')" prop="winOdd" align="center"/><!--贏得商機 Win odd%-->
          </el-table>
          <span slot="footer" class="dialog-footer">
              <div class="yt-btn yt-ml8" type="danger" @click="statusDialogTable = false">{{$t('button.close')}}</div><!--关闭-->
          </span>
        </el-dialog>
      </div>
      <div class="pagination-container" style="padding: 0 20px 10px">
        <el-pagination @size-change="handleSizeChange" @current-change="handleCurrentChange" background :current-page.sync="listQuery.page" :page-sizes="[10, 20, 30, 50, 100, 200]" :page-size="listQuery.limit" layout="total, sizes, prev, pager, next, jumper" :total="total"></el-pagination>
      </div>
    </div>

    <!--弹窗-->
    <!--'新增' : '编辑'-->
    <el-dialog :title="!dialogForm.id ? $t('button.new') : $t('button.edit')" :visible.sync="dictDialogVisible" :close-on-click-modal="false" :before-close="dialogClose" class="yt-dialogForm-box">
      <el-form :rules="rules" ref="rulesForm" :inline="true" :model="dialogForm" label-width="100px" class="yt-dialogForm">

        <el-form-item label="Account" prop="bu">
          <el-select clearable filterable v-model="dialogForm.bu" :placeholder="$t('placeholder.choose')" @change="setBu">
            <el-option v-for="item in buData" :key="item.bu" :label="item.bu" :value="item.bu"></el-option>
          </el-select>
        </el-form-item>
        <el-form-item :label="$t('specialApplication.maintenance.country')" prop="country"><!--国别-->
          <template>
            <dict-select :disabled="true" v-model="dialogForm.country" code="country" @change="setBg" clearable></dict-select>
          </template>
        </el-form-item>
        <el-form-item label="Category" prop="bg">
          <el-select disabled v-model="dialogForm.bg" :placeholder="$t('placeholder.choose')" @change="changeBg">
            <el-option v-for="item in setBgList" :key="item" :label="item" :value="item"></el-option>
          </el-select>
        </el-form-item>
        <el-form-item label="財務模式" prop="">
          <dict-select v-model="dialogForm.clientType" code="clientType" :clearable="true"></dict-select>
        </el-form-item>

        <el-form-item label="Territory" prop="territory">
          <dict-select v-model="dialogForm.territory" code="territory" clearable></dict-select>
        </el-form-item>

        <el-form-item v-show="dialogForm.projectNo" :label="$t('specialApplication.maintenance.projectNo')" prop="projectNo">
          <el-input v-model="dialogForm.projectNo" :placeholder="$t('specialApplication.maintenance.eneterProject')" ></el-input>
        </el-form-item>

        
          <el-form-item label="Client" prop="clientName" class="no_error">
            <!--请输入客户简称或客户全称-->
            <!-- <el-autocomplete clearable v-model="dialogForm.clientName" :fetch-suggestions="getCustomerList" :placeholder="$t('specialApplication.maintenance.enterCustomerName')" @select="setCustomer" style="width:160%"></el-autocomplete> -->
            <!--找不到相关客户，请点击此处新增客户。-->
            <!-- <span v-if="!clientStatus" v-show="!clientStatusYla" class="item_tips"> <span @click="goCustom">{{$t('specialApplication.maintenance.noFoundCustomer')}}</span></span> -->
            <popover-select @setValue="setCustomer" @goCustomer="goCustom" selectType="customer" :placeholder="$t('specialApplication.maintenance.enterCustomerName')" valueObjName="customerShortName" v-model="dialogForm.clientName"></popover-select>
          </el-form-item>
      
        <el-row>
          <el-form-item label="BD Name" prop="bdName">
            <!--案名前缀需带上客户简称，如：客户_案名-->
            <el-input v-model="dialogForm.bdName" :placeholder="$t('specialApplication.maintenance.bdNameTips')" style="width:160%"></el-input>
          </el-form-item>
        </el-row>
        <el-row>
          <el-form-item label="Contact window">
            <!--请输入姓名及职称(半形括号)，格式参考：张三(经理)-->
            <el-input v-model="dialogForm.contactWindow" :placeholder="$t('specialApplication.maintenance.contractWindow')" style="width:200%"></el-input>
          </el-form-item>
        </el-row>
        <el-row>
          <el-form-item label="Decision maker">
            <!--请输入姓名及职称(半形括号)，格式参考：张三(经理)-->
            <el-input v-model="dialogForm.decisionMaker" :placeholder="$t('specialApplication.maintenance.contractWindow')" style="width:200%"></el-input>
          </el-form-item>
        </el-row>

        <el-form-item label="Start Date" prop="startDate">
          <!--选择日期-->
          <el-date-picker v-model="dialogForm.startDate" type="date" :placeholder="$t('specialApplication.maintenance.chooseDate')" value-format=" yyyy-MM-dd" format="yyyy-MM-dd">
          </el-date-picker>
        </el-form-item>

        <el-form-item label="預計報價日"  prop="forecastMonth">
          <!--请选择forecast Month-->
          <el-date-picker v-model="dialogForm.forecastMonth" type="date" value-format="yyyy-MM-dd" format="yyyy-MM-dd" :placeholder="$t('specialApplication.maintenance.selectForecastMonth')"/>
        </el-form-item>

        <el-row>
          <el-form-item label="Task" >
            <!--Task-->
            <el-input v-model="dialogForm.task" :disabled="taskFlag" :placeholder="$t('placeholder.content')" style="width:160%"></el-input>
          </el-form-item>
        </el-row>

        <el-form-item label="Target Date" >
          <!--选择日期-->
          <el-date-picker v-model="dialogForm.targetDate" :disabled="targetFlag" type="date" :placeholder="$t('specialApplication.maintenance.chooseDate')" value-format=" yyyy-MM-dd" format="yyyy-MM-dd">
          </el-date-picker>
        </el-form-item>

        <el-form-item label="實際報價日">
          <!--选择日期-->
          <el-date-picker v-model="dialogForm.proposalDate" type="date" :placeholder="$t('specialApplication.maintenance.chooseDate')" value-format=" yyyy-MM-dd" format="yyyy-MM-dd">
          </el-date-picker>
        </el-form-item>

        <el-form-item label="Target Quarter">
          <yt-time-quarter :targetQuarterDate.sync="dialogForm.targetQuarterDate" :placeholder="$t('specialApplication.maintenance.targetQuarterDate')" v-model="dialogForm.targetQuarter" :disabled="(dialogForm.targetMonth!==''&&dialogForm.targetMonth!==null)? true : false"></yt-time-quarter>
        </el-form-item>

        <el-form-item label="預計簽約日"  prop="targetMonth">
          <!--请选择Target Month-->
          <el-date-picker v-model="dialogForm.targetMonth" type="month" value-format="yyyy-MM" format="yyyy-MM" :placeholder="$t('specialApplication.maintenance.selectTargetMonth')"/>
        </el-form-item>

        <el-form-item label="Sales" prop="sales">
          <!--请输入sales员工编号-->
          <!-- <el-autocomplete clearable v-model="dialogForm.sales" :fetch-suggestions="getSalesList" :placeholder="$t('specialApplication.maintenance.eneterSales')" @select="setSales"></el-autocomplete> -->
          <popover-select @setValue="setSales" selectType="user" :placeholder="$t('specialApplication.maintenance.eneterSales')" valueObjName="ename" v-model="dialogForm.sales"></popover-select>
        </el-form-item>

        <el-form-item label="Presales" prop="presales">
          <!--请输入presales员工编号-->
          <!-- <el-autocomplete clearable v-model="dialogForm.presales" :fetch-suggestions="getPreSalesList" :placeholder="$t('specialApplication.maintenance.enterPreSales')" @select="setPresales"></el-autocomplete> -->
          <popover-select @setValue="setPresales" selectType="user" :placeholder="$t('specialApplication.maintenance.enterPreSales')" valueObjName="ename" v-model="dialogForm.presales"></popover-select>
        </el-form-item>
        <el-form-item label="PM" prop="pm">
          <!--请输入pm员工编号-->
          <!-- <el-autocomplete clearable v-model="dialogForm.sales" :fetch-suggestions="getSalesList" :placeholder="$t('specialApplication.maintenance.eneterSales')" @select="setSales"></el-autocomplete> -->
          <popover-select @setValue="setPm" selectType="user" :placeholder="$t('specialApplication.maintenance.enterPm')" valueObjName="ename" v-model="dialogForm.pm"></popover-select>
        </el-form-item>

          <el-form-item label="董事會列管年度" >
            <!--选择日期-->
            <el-date-picker v-model="dialogForm.directorDate" :disabled="directorDateFlag" type="year" :placeholder="$t('specialApplication.maintenance.chooseDate')" value-format="yyyy" format="yyyy">
            </el-date-picker>
          </el-form-item>
        <el-form-item label="Estimated Revenue">
          <div v-check-submit tabindex="0">
            <el-input style="display: none" v-model="dialogForm.estimatedBudget" type="number" :placeholder="$t('placeholder.content')"></el-input>
            <div class="box1" style="border: 1px solid #dcdfe6;text-align: left" v-format="'#,##0'" :placeholder="$t('placeholder.content')">{{ dialogForm.estimatedBudget }}</div>
          </div>
        </el-form-item>
        <el-form-item label="Estimated cost">
          <div v-check-submit tabindex="0">
            <el-input style="display: none" v-model="dialogForm.estimatedCost" type="number" :placeholder="$t('placeholder.content')"></el-input>
            <div class="box1" style="border: 1px solid #dcdfe6;text-align: left" v-format="'#,##0'" :placeholder="$t('placeholder.content')">{{ dialogForm.estimatedCost }}</div>
          </div>
        </el-form-item>
         <el-form-item label="Estimated Revenue(this year)">
          <div v-check-submit tabindex="0">
            <el-input style="display: none" v-model="dialogForm.estimatedRevenueThis" type="number" :placeholder="$t('placeholder.content')"></el-input>
            <div class="box1" style="border: 1px solid #dcdfe6;text-align: left" v-format="'#,##0'" :placeholder="$t('placeholder.content')">{{ dialogForm.estimatedRevenueThis }}</div>
          </div>
        </el-form-item>

        <el-form-item label="Estimated Cost(this year)">
          <div v-check-submit tabindex="0">
            <el-input style="display: none" v-model="dialogForm.estimatedCostThis" type="number" :placeholder="$t('placeholder.content')"></el-input>
            <div class="box1" style="border: 1px solid #dcdfe6;text-align: left" v-format="'#,##0'" :placeholder="$t('placeholder.content')">{{ dialogForm.estimatedCostThis }}</div>
          </div>
        </el-form-item>


        <el-form-item label="董事會列管收入">
          <div v-check-submit tabindex="0">
            <el-input style="display: none" v-model="dialogForm.directorIncome" type="number" :disabled="directorIncomeFlag" :placeholder="$t('placeholder.content')"></el-input>
            <div class="box1" style="border: 1px solid #dcdfe6;text-align: left" v-format="'#,##0'" :placeholder="$t('placeholder.content')">{{ dialogForm.directorIncome }}</div>
          </div>
        </el-form-item>


          <el-form-item label="董事會列管成本">
          <div v-check-submit tabindex="0">
            <el-input style="display: none" v-model="dialogForm.directorCost" type="number" :disabled="directorCostFlag" :placeholder="$t('placeholder.content')"></el-input>
            <div class="box1" style="border: 1px solid #dcdfe6;text-align: left" v-format="'#,##0'" :placeholder="$t('placeholder.content')">{{ dialogForm.directorCost }}</div>
          </div>
        </el-form-item>
        <el-form-item label="Status" prop="status">
          <span slot="label">Status <i class="el-icon-question icon_question" @click="statusDialogTable = true"></i></span>
          <el-select clearable  v-model="dialogForm.status" :placeholder="$t('placeholder.choose')">
                  <el-option v-for="item in demandStatusList" :key="item.label" :label="item.label" :value="item.label"></el-option>
            </el-select>
        </el-form-item>
        <el-form-item label="End Date" prop='endDate'>
          <!--选择日期-->
          <el-date-picker v-model="dialogForm.endDate" type="date" :disabled="disableFlag" :placeholder="$t('specialApplication.maintenance.chooseDate')" value-format=" yyyy-MM-dd" format="yyyy-MM-dd"></el-date-picker>
        </el-form-item>
        <!--成案否-->
        <el-form-item :label="$t('specialApplication.maintenance.isFinishValue')" prop="isFinish">
          <dict-select v-model="dialogForm.isFinish" code="NorY" clearable></dict-select>
        </el-form-item>
    
        <el-row>
          <el-form-item label="進度說明(Sales&Presales)" prop="actionsSales">
            <el-input type="textarea" autosize v-model="dialogForm.actionsSales" :placeholder="$t('placeholder.content')" style="width:100%"></el-input>
          </el-form-item>
          <el-form-item label="Lately Daily-Sales" prop="latelyDailySales" :style="{display : !dialogForm.id ? 'none' : ''}">
            <!--sales日报内容-->
            <el-input type="textarea" autosize :readonly="true" v-model="dialogForm.latelyDailySales" style="width:100%"></el-input>
          </el-form-item>
        </el-row>
        
          <el-form-item label="進度說明(高階主管)" prop="actionsPresales">
            <el-input type="textarea" autosize v-model="dialogForm.actionsPresales" :placeholder="$t('placeholder.content')" style="width:100%"></el-input>
          </el-form-item>
          <el-form-item label="Lately Daily-Presales" prop="latelyDailyPresales" :style="{display : [!dialogForm.id ? 'none' : '']}">
            <!--presales日报内容-->
            <el-input type="textarea" autosize :readonly="true" v-model="dialogForm.latelyDailyPresales"  style="width:100%" ></el-input>
          </el-form-item>


        

         
        
      </el-form>
      <span slot="footer" class="dialog-footer">
        <div class="yt-btn yt-btn-ys" type="primary" @click="editorDict('rulesForm')">{{$t('button.determine')}}</div>
        <div class="yt-btn yt-ml8" type="danger" @click="resetForm('rulesForm')">{{$t('button.cancel')}}</div>
      </span>
    </el-dialog>
  </div>
</template>

<script>
  // import { delList } from '@/api/bu/index'
  import {
    demandQuery,
    demand,
    demandUpdate,
    demandDelete,
    targetCheck,
    queryAllUser,
    queryAllCustomer
  } from '@/api/specialApplication/index';
  import { selectBuData, listbgAndbu, getDeptByBuAndCountry } from '@/api/bu/index';
  import customerReq from '@/api/customer';
  import formatter from '@/utils/formatter';
  import YtTableTitle from '@/components/yt-table-title/index';
  import { queryDisplayBlock } from '@/api/pmoReport/projectRevenue';
  import { mapGetters } from 'vuex';
  import YtTimeQuarter from '@/components/yt-time-quarter/main.vue';
  import popoverSetQuery from '@/components/popover-setQuery/index.vue';
  import popoverSelect from '@/components/popover-select/index.vue';
  import { getInputValue, delcommafy } from '@/utils/thousandSemicolonUtils.js'

  export default {
    name: 'maintenance',
    // mixins: [mixins],
    components: {
      YtTimeQuarter,
      popoverSelect,
      YtTableTitle,
      popoverSetQuery,
      'dict-select': () => import('@/components/Dict/dictValueSelect')
    },
    data() {
      const validateClientName = (rule, value, callback) => {
        if (!value) {
          this.clientStatus = false
          this.clientStatusYla = false
          callback(new Error(this.$t('specialApplication.maintenance.errorCustomerTips'))); // 找不到相关客户，请点击此处新增客户。
        } else {
          if (this.client !== this.dialogForm.client) {
            this.clientStatus = false
            this.clientStatusYla = false
            callback(new Error(this.$t('specialApplication.maintenance.errorCustomerTips'))); // 找不到相关客户，请点击此处新增客户。
          } else {
            this.clientStatus = true
            this.clientStatusYla = true
            callback()
          }
          // if (this.customerList.findIndex(item => this.dialogForm.clientName === item.customerShortName && this.dialogForm.client === item.id) < 0) {
          //   callback(new Error('找不到相关客户，请点击此处新增客户。'));
          //   this.clientStatus = false
          // } else {
          //   callback()
          //   this.clientStatus = true
          // }
        }
      };
      const validateSales = (rule, value, callback) => {
        if (!value) {
          this.salesStatus = false
          callback(new Error(this.$t('specialApplication.maintenance.errorSalesTips'))); // 请选择Sales'errorSalesTips
        } else {
          if (this.sales !== value) {
            this.salesStatus = false
            callback(new Error(this.$t('specialApplication.maintenance.errorSalesTips'))); // 请选择Sales'
          } else {
            this.salesStatus = true
            callback()
          }
          // if (this.userList.findIndex(item => this.dialogForm.sales === item.ename && this.dialogForm.salesId === item.id) < 0) {
          //   callback(new Error('请选择Sales'));
          // } else {
          //   callback()
          // }
        }
      };
      const validatePresales = (rule, value, callback) => {
        if (!value) {
          this.presalesStatus = false
          callback(new Error(this.$t('specialApplication.maintenance.errorPreSalesTips'))); // 请选择PresaleserrorPreSalesTips
        } else {
          if (this.presales !== value) {
            this.presalesStatus = false
            callback(new Error(this.$t('specialApplication.maintenance.errorPreSalesTips'))); // 请选择Presales
          } else {
            this.presalesStatus = true
            callback()
          }
          // if (this.userList.findIndex(item => this.dialogForm.presales === item.ename && this.dialogForm.presalesId === item.id) < 0) {
          //   callback(new Error('请选择Presales'));
          // } else {
          //   callback()
          // }
        }
      }
      return {
        userName: this.$store.getters.info.username,
        dateDisabled1: true,
        dateDisabled2: true,
        dateDisabled3: true,
        isValues: [
          { value: '1', label: '有值' },
          { value: '0', label: '無值' }],
        demandDeltePermision: false, // 是否有删除权限
        bu: [],
        disableFlag: false, // 是否可以选择end Date
        taskFlag: true, // 是否可以选择Task
        targetFlag: true, // 是否可以选择Target Date
        directorIncomeFlag: true, // 是否可以选择董事會列管收入
        directorCostFlag: true, // 是否可以选择董事會列管成本
        directorDateFlag: true, // 是否可以选择董事會列管年度
        blockNameCode: 'maintenance',
        displayBlockNameStr: {},
        displayBlockNameList: {},
        TableTitleVisible: false,
        showI: true,
        timeQuarter: '',
        demandStatusList: this.$store.getters.allDic.demandStatus,
        listAll: this.$store.getters.allDic,
        listMapAll: this.$store.getters.allMapDic,
        authority: this.$store.getters.allDic.Authority,
        statusAuthority: this.$store.getters.allDic.StatusAuthority,
        buListAll: {},
        statusAll: {},
        config: Config.I18n,
        formatter,
        form: {
          username: undefined,
          name: undefined,
          sex: 'comm_sex_man',
          password: undefined,
          description: undefined,
          departName: undefined,
          departId: undefined,
          groupType: undefined,
          email: undefined
        },
        customerList: [],
        userList: [],
        buList: [],
        buData: [],
        bgList: [],
        setBgList: [],
        setBuList: [],
        options: [
          { label: '1', value: '1' },
          { label: '2', value: '2' },
          { label: '3', value: '3' }
        ],
        isCaseOptions: [{ label: '1', value: '1' }, { label: '2', value: '2' }],
        subtotal: {},
        list: null, // 用于表格渲染数据
        total: null,
        tableListist: null, // 缓存原始数据
        listLoading: true,
        listQuery: {
          order: '', // 降序（desc）/升序（asc）
          orderBy: '', // 排序字段
          page: 1,
          limit: 10,
          bdName: '',
          country: '',
          bu: [],
          name: '',
          client: '',
          bg: '',
          status: [],
          estimatedBudgetMaxString: '',
          estimatedBudgetMinString: '',
          estimatedBudgetMax: '',
          estimatedBudgetMin: '',
          isOuterStartValue: '',
          isInnerStartValue: '',
          isBidBeforeValue: ''
        },
        selectionList: [],
        tableKey: 0,
        startDate: '',
        dictDialogVisible: false,
        sales: '',
        presales: '',
        client: '',
        dialogForm: {
          id: '',
          buId: '',
          country: '',
          bg: '',
          bu: '',
          clientType: '',
          territory: '',
          client: '',
          bdNo: '',
          bdOrder: '',
          bdName: '',
          contactWindow: '',
          decisionMaker: '',
          sales: '',
          salesId: '',
          presales: '',
          presalesId: '',
          pm: '',
          pmId: '',
          startDate: '',
          endDate: '',
          proposalDate: '',
          targetQuarter: '',
          targetMonth: '',
          forecastMonth: '',
          estimatedBudget: '',
          estimatedCost: '',
          status: '',
          actionsSales: '',
          actionsPresales: '',
          isFinish: 'N',
          projectNo: '',
          latelyDailySales: '',
          latelyDailyPresales: '',
          outerStartMeetingDateIs: '',
          bidBeforeMeetingDate: '',
          innerStartMeetingDate: '',
          outerStartMeetingDate: '',
          estimatedCostThis: '',
          estimatedRevenueThis: '',
          task: '',
          targetDate: '',
          directorIncome: '',
          directorCost: '',
          directorDate: ''
        },
        rules: {
          country: [
            {
              required: true,
              message: this.$t('specialApplication.maintenance.pleaseSelectCountry'), // 请选择国别
              trigger: 'blur'
            }
          ],
          bg: [
            {
              required: true,
              message: this.$t('specialApplication.maintenance.pleaseSelectBG'), // 请选择BG
              trigger: 'blur'
            }
          ],
          bu: [
            {
              required: true,
              message: this.$t('specialApplication.maintenance.pleaseSelectBU'), // 请选择BU
              trigger: 'blur'
            }
          ],
          clientType: [
            {
              required: true,
              message: this.$t('specialApplication.maintenance.pleaseSelectClientType'), // 请选择Client Type
              trigger: 'blur'
            }
          ],
          territory: [
            {
              required: true,
              message: this.$t('specialApplication.maintenance.pleaseSelectTerritory'), // 请选择Territory
              trigger: 'blur'
            }
          ],
          clientName: [
            {
              required: true,
              validator: validateClientName,
              trigger: 'change'
            }
          ],
          bdName: [
            {
              required: true,
              message: this.$t('specialApplication.maintenance.pleaseEnterBD'), // 请输入BD Name
              trigger: 'blur'
            }
          ],
          sales: [
            {
              required: true,
              validator: validateSales,
              trigger: 'change'
            }
          ],
          targetMonth: [
            {
              required: true,
              message: this.$t('specialApplication.maintenance.targetMonth'), // 请选择targetMonth
              trigger: 'blur'
            }
          ], 
          forecastMonth: [
            {
              required: true,
              message: this.$t('specialApplication.maintenance.forecastMonth'), // 请选择targetMonth
              trigger: 'blur'
            }
          ], 
         startDate: [
            {
              required: true,
              message: this.$t('specialApplication.maintenance.pleaseSelectStartDate'), // 请选择Start Date
              trigger: 'blur'
            }
          ], 
          presales: [
            {
              required: true,
              validator: validatePresales,
              trigger: 'change'
            }
          ],
          status: [
            {
              required: true,
              message: this.$t('specialApplication.maintenance.pleaseSelectStatus'), // 请选择status
              trigger: 'blur'
            }
          ],
          isFinish: [
            {
              required: true,
              message: this.$t('specialApplication.maintenance.errorPreSalesTips'), // 请选择成案否
              trigger: 'blur'
            }
          ]
        },
        statusDialogTable: false,
        dialogList: [
          { name: this.$t('specialApplication.maintenance.notice'), status: '1_規劃中', winOdd: '10%', nameText: '01-Noticing' }, // 通知
          {
            name: this.$t('specialApplication.maintenance.identify'), // 確認商機存在，業主預算和時間尚未定羲清楚
            status: '2_報價中',
            winOdd: '20%',
            nameText: '02-Noticed/Identifying'
          },
          {
            name: this.$t('specialApplication.maintenance.validate'), // 驗證確認後，有預算或執行時間
            status: '3_議價中',
            winOdd: '30%',
            nameText: '03-Identifed/Validating'
          },
          {
            name: this.$t('specialApplication.maintenance.qualidate'), // 經驗確認後，有預算或執行時間
            status: '4_簽約中',
            winOdd: '40%',
            nameText: '04-Validate/Qualifying'
          },
          {
            name: this.$t('specialApplication.maintenance.proposed'), // 提交建議書
            status: '3_議價',
            winOdd: '50%',
            nameText: '05-Proposal submit'
          },
          {
            name: this.$t('specialApplication.maintenance.proposedAward'), // 預估可能得標
            status: '3_議價',
            winOdd: '60%',
            nameText: '06-Proposed award'
          },
          {
            name: this.$t('specialApplication.maintenance.award'), // 口頭承諾此合約
            status: '3_議價',
            winOdd: '70%',
            nameText: '07-Gaining Agreement'
          },
          {
            name: this.$t('specialApplication.maintenance.close'), // 簽約
            status: '5_在建工程',
            winOdd: '100%',
            nameText: '08-Cond Agreement/Closing'
          },
          { name: 'No go', status: 'No Bid', winOdd: '', nameText: '09-No Bid' },
          {
            name: this.$t('specialApplication.maintenance.customerNotpursue'), // 客戶不做
            status: 'Customer didn`t pursue',
            winOdd: '',
            nameText: '10-Customer Did Not Pursue'
          },
          {
            name: this.$t('specialApplication.maintenance.lost'), // 輸給競爭對手
            status: 'Lost',
            winOdd: '',
            nameText: '11-Lost to Competion'
          },
          { name: '', status: 'Pending', winOdd: '' }
        ],
        clientStatusYla: true,
        clientStatus: false,
        salesStatus: false,
        presalesStatus: false
      };
    },
    created() {
      this.getQuery();
    },
    mounted() {
      // console.log(this.elements)
      this.demandDeltePermision = this.elements['demandPermissionMaintain.delete']
      console.log('permission', this.demandDeltePermision)
      this.getColumn();
      this.getAll();
      this.getList();
      this.init()
      this.querySetBg(this.listQuery.country)
      this.queryChangeBg(this.listQuery.bg)
      this.loadBg()
    },
    watch: {
      'dialogForm.status'(val) {
        if (val === '5_在建工程'  || val === '8_Close' || val === 'No Bid' || val === 'Customer didn\'t pursue' || val === 'Lost' || val === 'Pending') {
          const item = [{ required: true, message: this.$t('specialApplication.maintenance.pleaseEnterEndDate'), trigger: 'blur' }] // 请输入End Date
          this.$set(this.rules, 'endDate', item)
          this.disableFlag = false
        } else {
          this.$set(this.rules, 'endDate', {})
          this.disableFlag = true
          this.dialogForm.endDate = ''
        }
      },
      'dialogForm.targetMonth'() {
        console.log()
        if (this.dialogForm.targetMonth) {
          const arr = this.dialogForm.targetMonth.split('-')
          const str = `${arr[0].substr(arr[0].length - 2, 2)}'Q${Math.ceil(arr[1] / 3)}`
          const year = arr[0]
          const quarter = Math.ceil(arr[1] / 3)
          let month = '03'
          if (quarter === 1) {
            month = '03'
          } else if (quarter === 2) {
            month = '06'
          } else if (quarter === 3) {
            month = '09'
          } else if (quarter === 4) {
            month = '12'
          }

          this.$set(this.dialogForm, 'targetQuarterDate', year + '-' + month + '-01')
          this.$set(this.dialogForm, 'targetQuarter', str)
        }
      }
    },
    computed: {
      ...mapGetters(['elements'])
    },
    methods: {
      check(el, name) {
        if (this.listQuery[name]) {
          const rule = /^[-]?\d*$/
          const inputVal = delcommafy(this.listQuery[name]);
          if (rule.test(inputVal)) {
            this.listQuery[name] = getInputValue(el);
          } else {
            this.$notify({
              title: this.$t('tips.fail'), // 失败
              message: 'Estmated budget區間只能輸入數字',
              type: 'warning'
            });
          }
        }
      },
      inputMoney(el, name) {
        console.log(this.listQuery[name], 'this.listQuery[name]')
        // 验证一下是否为数字
        this.check(el, name)
      },
      cancel(val) {
        if (val) {
          this.getColumn();
        }
        this.TableTitleVisible = false
      },
      // 获取初始的栏位
      getColumn() {
        const data = {
          tableName: this.blockNameCode,
          userId: this.$store.getters.info.id
        }
        this.getMixinColumn(data)
      },
      getMixinColumn(data) {
        this.displayBlockNameStr = {}
        queryDisplayBlock(data).then(res => {
          if (res.status === 200) {
            this.displayBlockNameList = res.data
            for (const i in this.displayBlockNameList) {
              this.displayBlockNameStr[this.displayBlockNameList[i]] = true
            }
          }
        })
      },
      renderHeader1(h, { column }) {
        const header = column.label.split(' ');
        return [h('p', [
          h('p', {}, header[0]),
          h('p', {}, header[1]),
          h('span', {}, header[2])
        ])];
      },
      // 获取弹框的栏位
      setUp() {
        // 设置
        console.log(this.displayBlockNameList)
        this.TableTitleVisible = true
      },
      clickShow(val) {
        this.showI = val
      },
      renderHeader(h) {
        return h('div', {
          attrs: {
            class: 'cell' // ele原来样式
          },
          domProps: {
            innerHTML: this.$t('specialApplication.maintenance.saleCode') + '<br/>Siebel Sales Stage Code' // 銷售階段碼
          }
        })
      },
      clickRow(row, event, column) {
        if (column.property !== 'id' && column.property !== 'countryName' && column.property !== 'bg') {
          this.selectionList = []
          this.selectionList.push(row)
          console.log(this.selectionList)
          this.handlePreserve('edit')
        }
      },
      getAll() {
        // 用来做验证
        queryAllUser({}).then(res => {
          this.userList = res.data.rows
        })

        queryAllCustomer({}).then(res => {
          this.customerList = res.data.rows
        })
      },
      getMyQuotes() {
        // 需求报价单维护
        if (this.selectionList.length <= 0) {
          this.$notify({
            title: this.$t('tips.fail'), // 失败
            message: this.$t('placeholder.choose'), // 请选择
            type: 'warning'
          });
          return;
        }
        if (this.selectionList[0].isFinishValue === 'Y') {
          this.$notify({
            title: this.$t('tips.fail'), // 失败
            message: this.$t('specialApplication.maintenance.priceTips'), // 当成案否为Y时，不可业务报价
            type: 'warning'
          });
          return;
        }
        const id = this.selectionList[0].id;
        this.$router.push({
          path: '/demandManager/demandQuotation',
          query: { title: 'update', id }
        });
        window.sessionStorage.setItem(
          'maintenanceDetail',
          JSON.stringify(this.selectionList[0])
        );
      },
      setSales(item) {
        this.sales = item.ename
        this.$set(this.dialogForm, 'salesId', item.id)
      },
      setPresales(item) {
        this.presales = item.ename
        this.$set(this.dialogForm, 'presalesId', item.id)
      },
      setPm(item) {
        this.pm = item.ename
        this.$set(this.dialogForm, 'pmId', item.id)
      },
      setCustomer(item) {
        this.client = item.id
        this.$set(this.dialogForm, 'client', item.id)
      },
      selectCustomer(item) {
        this.listQuery.client = item.id;
      },
      getCustomerList(queryString, cb) {
        customerReq.pageClient({ clientName: queryString }).then(res => {
          const customerList = res.data.rows;
          if (res.data.rows.length === 0) {
            this.client = ''
          }
          for (let i = 0; i < customerList.length; i++) {
            customerList[i].value = customerList[i].customerShortName;
          }
          cb(customerList);
        });
      },

      querySetBg(country) {
        const param = {}
        if (country) {
          param.country = country
          param.bu = []
          param.bg = []
          getDeptByBuAndCountry(param).then(res => {
            this.buList = res.data.buList;
            this.bgList = res.data.bgList;
            this.setBgList = res.data.bgList;
            this.setBuList = res.data.buList;
          })
        } else {
          this.loadBg()
        }
      },
      queryChangeBu(val) {
        // 联动bg
        if (val === '') {
          this.getBg()
        } else {
          listbgAndbu({ bu: val, bg: '' }).then(res => {
            this.bgList = res.data
          });
        }
      },
      queryChangeBg(val) {
        this.changeBg(val)
        // 联动bu
      },
      setBg(country) {
        const param = {}
        if (country) {
          param.country = country
          param.bu = []
          param.bg = []
          getDeptByBuAndCountry(param).then(res => {
            this.buList = res.data.buList;
            this.bgList = res.data.bgList;
            this.setBgList = res.data.bgList;
            this.setBuList = res.data.buList;
          })
        } else {
          this.loadBg();
        }
        selectBuData().then(res => {
          this.buData = res.data;
        });
      },
      loadBg() {
        const param = {}
        getDeptByBuAndCountry(param).then(res => {
          this.buList = res.data.buList;
          this.bgList = res.data.bgList;
          this.setBgList = res.data.bgList;
          this.setBuList = res.data.buList;
        })
      },
      setBu() {
        this.buData.forEach(res => {
          if (res.bu === this.dialogForm.bu) {
            this.dialogForm.buId = res.id
            this.dialogForm.bg = res.bg
            this.dialogForm.country = res.country
          }
        })
      },
      changeBg(row) {
        console.info(row)
        // this.bu = []
        // const bgSet = []
        // if (row !== '') {
        //   bgSet.push(row)
        // }
        const param = {}
        param.country = this.listQuery.country
        // param.bg = bgSet
        param.bg = row
        param.bu = []
        getDeptByBuAndCountry(param).then(res => {
          this.buList = res.data.buList
        })
      },
      changeBu(row) {
        if (row.length === 0) {
          this.bu = []
        }
      },
      isBidBeforeMeetingDateValue(row) {
        if (row === '1') {
          this.dateDisabled1 = false;
        } else {
          this.dateDisabled1 = true;
          this.isBidBeforeValue = ''
        }
      },
      isInnerStartMeetingDateValue(row) {
        if (row === '1') {
          this.dateDisabled2 = false;
        } else {
          this.dateDisabled2 = true;
          this.isInnerStartValue = ''
        }
      },
      isOuterStartMeetingDateValue(row) {
        if (row === '1') {
          this.dateDisabled3 = false;
        } else {
          this.dateDisabled3 = true;
          this.isOuterStartValue = '';
        }
      },
      exportExcel() {
        var arr = [];
        this.listQuery.bu = this.bu

        if(this.listQuery.bu.length !==0){
          this.listQuery.bu.forEach((elem, index) => {
              if(elem.indexOf('&')!==-1){
                arr.push(elem.replace('&','*'))
              }else {
                arr.push(elem)
              }
          });
          this.listQuery.bu = arr
        }
        
        let str = ''; // 传参数
        for (const i in this.listQuery) {
          if (this.listQuery[i]) {
            str += i + '=' + this.listQuery[i] + '&';
          }
        }

        if (this.$store.getters.info && this.$store.getters.info.id) {
          str = str + 'createBy=' + this.$store.getters.info.id;
        }
      console.info(str) ;
        const a = document.createElement('a');
        const href = '/api/admin/excel/excelFireTenement?' + str;
        a.download = Date.now();
        a.href = href;
        a.click();
      },
      getQuery() {
        const searchMaintenance = window.sessionStorage.getItem('searchMaintenance');
        if (searchMaintenance) {
          this.listQuery = JSON.parse(searchMaintenance);
        }
      },
      targetCheck() {
        this.listLoading = true;
        targetCheck()
          .then(response => {
            this.list = response.data.rows;

            for (let i = 0; i < this.list.length; i++) {
              if (this.list[i].winOdds) {
                this.list[i].winOddsName = this.list[i].winOdds + '%';
              }
              this.list[i].countryName = this.listMapAll.country[this.list[i].country];
              this.list[i].isFinishValue = this.listMapAll.NorY[this.list[i].isFinish];
              this.list[i].clientTypeName = this.listMapAll.clientType[this.list[i].clientType];
            }
            this.total = response.data.total;
            this.listLoading = false;
          })
          .catch(() => {
            this.listLoading = false;
            this.getList();
          });
      },
      demandQuery() {
        const bgSet = []
        const bg = []
        if (this.listQuery.bg.length !== 0) {
          // bgSet.push(this.listQuery.bg)
          // this.listQuery.bg = bgSet
        }else{
            this.listQuery.bg = bg
        }


        return new Promise(resolve => {
          this.listLoading = true;
          if (this.listQuery.startDate && this.listQuery.startDate.length > 0) {
            this.listQuery.startTime = this.listQuery.startDate[0];
            this.listQuery.endTime = this.listQuery.startDate[1];
          }else{
            this.$delete(this.listQuery,'startTime');
            this.$delete(this.listQuery,'endTime');
          }
          
          if (this.listQuery.bidBeforeMeetingDate && this.listQuery.bidBeforeMeetingDate.length > 0) {
            this.listQuery.bidBeforeMeetingDateStart = this.listQuery.bidBeforeMeetingDate[0];
            this.listQuery.bidBeforeMeetingDateEnd = this.listQuery.bidBeforeMeetingDate[1];
          }
          if (this.listQuery.innerStartMeetingDate && this.listQuery.innerStartMeetingDate.length > 0) {
            this.listQuery.innerStartMeetingDateStart = this.listQuery.innerStartMeetingDate[0];
            this.listQuery.innerStartMeetingDateEnd = this.listQuery.innerStartMeetingDate[1];
          }
          if (this.listQuery.outerStartMeetingDate && this.listQuery.outerStartMeetingDate.length > 0) {
            this.listQuery.outerStartMeetingDateStart = this.listQuery.outerStartMeetingDate[0];
            this.listQuery.outerStartMeetingDateEnd = this.listQuery.outerStartMeetingDate[1];
          }
          if (this.listQuery.estimatedBudgetMaxString) {
            const rule = /^[-]?\d*$/
            const inputVal = delcommafy(this.listQuery.estimatedBudgetMaxString);
            if (rule.test(inputVal)) {
              this.listQuery.estimatedBudgetMax = inputVal
            } else {
              this.$notify({
                title: this.$t('tips.fail'), // 失败
                message: 'Estmated budget區間只能輸入數字',
                type: 'warning'
              });
              return
            }
          } else {
            this.listQuery.estimatedBudgetMax = ''
          }
          if (this.listQuery.estimatedBudgetMinString) {
            const rule = /^[-]?\d*$/
            const inputVal = delcommafy(this.listQuery.estimatedBudgetMinString);
            if (rule.test(inputVal)) {
              this.listQuery.estimatedBudgetMin = inputVal
            } else {
              this.$notify({
                title: this.$t('tips.fail'), // 失败
                message: 'Estmated budget區間只能輸入數字',
                type: 'warning'
              });
              return
            }
          } else {
            this.listQuery.estimatedBudgetMin = ''
          }
          demandQuery(this.listQuery).then(response => {
            if (response.data.rows && response.data.rows.length > 0) {
              this.list = response.data.rows;
              this.subtotal = response.data.subtotal;
              Object.keys(this.subtotal).forEach(key => {
                this.subtotal[key] = String(this.subtotal[key]).replace(/\d{1,3}(?=(\d{3})+(\.|$))/g, '$&,')
              })
              for (let i = 0; i < this.list.length; i++) {
                if (this.list[i].winOdds) {
                  this.list[i].winOddsName = this.list[i].winOdds + '%';
                }
                this.list[i].countryName = this.listMapAll.country[this.list[i].country];
                this.list[i].isFinishValue = this.listMapAll.NorY[this.list[i].isFinish];
                this.list[i].clientTypeName = this.listMapAll.clientType[this.list[i].clientType];
              }
            } else {
              this.list = [];
              this.subtotal = {};
            }
            this.total = response.data.total;
            this.listLoading = false;
            resolve()
          });
        })
      },
      async getList() {
        await this.demandQuery()
        // 全选
        // this.list.forEach(row => {
        //   this.$refs.dataTable.toggleRowSelection(row);
        // });
      },
      handleFilter() {
        this.listQuery.bu = this.bu
        this.getList();
      },
      reset() {
        this.bu = []
        this.listQuery.bu = ''
        this.listQuery = {
          order: '', // 降序（desc）/升序（asc）
          orderBy: '', // 排序字段
          page: 1,
          limit: 10,
          bdName: '',
          country: '',
          bu: [],
          name: '',
          client: '',
          bg: '',
          status: [],
          estimatedBudgetMaxString: '',
          estimatedBudgetMinString: '',
          estimatedBudgetMax: '',
          estimatedBudgetMin: '',
          isOuterStartValue: '',
          isInnerStartValue: '',
          isBidBeforeValue: ''
        };
        this.getList();
        this.loadBg();
        this.isBidBeforeMeetingDateValue();
        this.isInnerStartMeetingDateValue();
        this.isOuterStartMeetingDateValue();
      },
      handleSizeChange(val) {
        this.listQuery.limit = val;
        window.sessionStorage.setItem(
          'searchMaintenance',
          JSON.stringify(this.listQuery)
        );
        this.getList();
      },
      handleCurrentChange(val) {
        this.listQuery.page = val;
        this.getList();
      },
      handleSelectionChange(val) {
        //  表格序号选中函数
        this.selectionList = val;
      },
      // 删除
      handleDelete() {
        let clientName = ''
        if (this.selectionList.length <= 0) {
          this.$notify({
            title: this.$t('tips.fail'), // '失败',
            message: this.$t('specialApplication.maintenance.pleaseSelectOne'), // 请选择一条记录
            type: 'warning'
          });
          return false
        }
        this.selectionList.forEach((row, i) => {
          clientName += clientName !== '' ? '、' + this.selectionList[i].bdName : this.selectionList[i].bdName
        })

        this.$confirm(this.$t('worksTargetEdit.notify.message4') + clientName + this.$t('worksTargetEdit.notify.message8') + this.selectionList.length + this.$t('worksTargetEdit.notify.message6') + this.$t('worksTargetEdit.notify.message7'), this.$t('worksTargetEdit.notify.message5'), {
          confirmButtonText: this.$t('worksTargetEdit.notify.confirmButtonText'),
          cancelButtonText: this.$t('worksTargetEdit.notify.cancelButtonText'),
          type: 'warning'
        }).then(() => {
          const arr = []; // 存放已修改的
          this.selectionList.forEach(item => {
            if (
              JSON.stringify(this.tableListist).indexOf(JSON.stringify(item)) < 0
            ) {
              arr.push(item);
            }
          })
          demandDelete(arr).then(res => {
            this.$notify({
              title: res.status === 200 ? this.$t('tips.success') : this.$t('tips.fail'), // '成功' : '失败',
              message: res.data,
              type: res.status === 200 ? 'success' : 'warning'
            });
            this.getList();
          });
        }).catch(() => {
          this.$message({ type: 'info', message: this.$t('worksTargetEdit.message.message2') });
        });
      },
      // 新增数据
      editorDict(formName) {
        const set = this.$refs;
        set[formName].validate(valid => {
          if (!this.clientStatus || !this.salesStatus || !this.presalesStatus) {
            return false
          }
          if (valid) {
            let myMap = new Map()
            for(const key in this.listMapAll.demandStatus){
              myMap.set(this.listMapAll.demandStatus[key],key);
            }

            if(this.dialogForm.status == 'No Bid' || this.dialogForm.status == "Customer didn't pursue" || this.dialogForm.status == "Lost" || this.dialogForm.status == "Pending"){
              this.dialogForm.winOdds ='';
            }else {
              // 设置winOdds
              this.dialogForm.winOdds = myMap.get(this.dialogForm.status);
            }
            console.log(this.dialogForm.status)
            console.log(this.dialogForm.winOdds)

            // 判断targetMonth和targetQuarter时间不能小于当前时间
            // const data = new Date()
            // const year = data.getFullYear()
            // const month = data.getMonth() + 1
            if (this.targetMonth) {
              // const targetMonth = this..targetMonth.split('-')
              // if (targetMonth[0] * 1 < year) {
              //   this.$message({
              //     message: this.$t('specialApplication.maintenance.noCanLetterNowMonth'), // Target Month时间不能小于当前时间
              //     type: 'error'
              //   });
              //   return
              // }
              // if (targetMonth[0] * 1 === year && targetMonth[1] * 1 < month) {
              //   this.$message({
              //     message: this.$t('specialApplication.maintenance.noCanLetterNowMonth'), // Target Month时间不能小于当前时间
              //     type: 'error'
              //   });
              //   return
              // }
            }
            if (this.targetQuarter) {
              // const years = year.toString().substr(year.toString().length - 2, 2)
              // const targetQuarter = this..targetQuarter.split('\'Q')
              // if (targetQuarter[0] * 1 < years * 1) {
              //   this.$message({
              //     message: this.$t('specialApplication.maintenance.noCanLetterNowQuarter'), // Target Quarter时间不能小于当前时间
              //     type: 'error'
              //   });
              //   return
              // }
              // if (targetQuarter[0] * 1 === years * 1 && targetQuarter[1] * 3 < month) {
              //   this.$message({
              //     message: this.$t('specialApplication.maintenance.noCanLetterNowQuarter'), // Target Quarter时间不能小于当前时间
              //     type: 'error'
              //   });
              //   return
              // }
            }
            // 字数校验
            if (this.dialogForm.actionsPresales && this.dialogForm.actionsPresales.length > 1000) {
              this.$message.error(this.$t('myDailyDetails.message.columns') + '「進度說明(高階主管)」' + this.$t('myDailyDetails.message.moreThan') + 1000 + this.$t('myDailyDetails.message.moreThanTwo'));
              return
            }
            if (this.dialogForm.actionsSales && this.dialogForm.actionsSales.length > 1000) {
              this.$message.error(this.$t('myDailyDetails.message.columns') + '「進度說明(Sales&Presales)」' + this.$t('myDailyDetails.message.moreThan') + 1000 + this.$t('myDailyDetails.message.moreThanTwo'));
              return
            }

            
            if(this.statusAuthority.length !==0){
                var use = true;

              for (let i = 0; i < this.statusAuthority.length; i++) {
                if(this.userName === this.statusAuthority[i].value){
                   use = false
                }
              }

              if(use && (this.dialogForm.status == 'No Bid' || this.dialogForm.status == "Customer didn't pursue" || this.dialogForm.status == "Lost" || this.dialogForm.status == "Pending")){
                this.$message({
                   message: '無修改Status 1~8以外之權限', 
                   type: 'error'
                 });
                 return
              }
            }

        
            console.info(this.dialogForm)

            if (this.dialogForm.id === '') {
              demand(this.dialogForm).then(res => {
                this.$notify({
                  title: res.status === 200 ? this.$t('specialApplication.maintenance.saveSuccess') : this.$t('tips.success'), // '保存成功' : '成功',
                  message: res.status === 201 ? this.$t('specialApplication.maintenance.saveFail') + res.data : this.$t('tips.success'), // 保存失败
                  type: res.status === 200 ? 'success' : 'warning'
                });
                if (res.status === 200) {
                  this.resetForm('rulesForm');
                  this.dictDialogVisible = false;
                  this.getList();
                }
              });
            } else {
              demandUpdate(this.dialogForm)
                .then(res => {
                  this.$notify({
                    title: res.status === 200 ? this.$t('specialApplication.maintenance.saveSuccess') : this.$t('tips.success'), // '保存成功' : '成功',
                    message: res.status === 201 ? this.$t('specialApplication.maintenance.saveFail') + res.data : this.$t('tips.success'), // 保存失败
                    type: res.status === 200 ? 'success' : 'warning'
                  });
                  if (res.status === 200) {
                    this.resetForm('rulesForm');
                    this.dialogClose()
                    this.getList();
                  }
                })
                .catch(() => {
                  this.getList();
                });
            }
          } else {
            return false;
          }
        });
      },
      // 新增按钮并重置数据
      newly() {      
        if (!this.dialogForm.country || this.dialogForm.id) {
          this.dialogForm = {
            id: '',
            buId: '',
            country: 'TW',
            bg: '',
            bu: '',
            clientType: '',
            territory: '',
            client: '',
            clientName: '',
            bdNo: '',
            bdOrder: '',
            bdName: '',
            contactWindow: '',
            decisionMaker: '',
            sales: '',
            salesId: '',
            presales: '',
            presalesId: '',
            pm: '',
            pmId: '',
            startDate: new Date(),
            endDate: '',
            proposalDate: '',
            targetQuarter: '',
            targetQuarterDate: null,
            targetMonth: '',
            forecastMonth: '',
            estimatedBudget: '',
            estimatedCost: '',
            status: '',
            actionsSales: '',
            actionsPresales: '',
            isFinish: 'N',
            projectNo: '',
            latelyDailySales: '',
            latelyDailyPresales: '',
            outerStartMeetingDateIs: '',
            bidBeforeMeetingDate: '',
            innerStartMeetingDate: '',
            outerStartMeetingDate: '',
            estimatedCostThis: '',
            estimatedRevenueThis: '',
            task: '',
            targetDate: '',
            directorIncome: '',
            directorCost: '',
            directorDate: ''
          };
        }
        if(this.authority.length !==0){
         for (let i = 0; i < this.authority.length; i++) {
            if(this.userName === this.authority[i].value){
               this.taskFlag = false;
                this.targetFlag = false;
                this.directorIncomeFlag = false;
                this.directorCostFlag = false;
                this.directorDateFlag = false;
            }
          }
        }
        this.setBg('');
        this.dictDialogVisible = true;   
      },
      handlePreserve(val) {


        // 修改保存函数
        if (this.selectionList.length <= 0) {
          this.$notify({
            title: this.$t('tips.fail'), // 失败
            message: this.$t('specialApplication.maintenance.noSelect'), // 您还未选择
            type: 'warning'
          });
          return;
        }
        const arr = []; // 存放已修改的
        this.selectionList.forEach(item => {
          if (JSON.stringify(this.tableListist).indexOf(JSON.stringify(item)) < 0) {
            arr.push(item);
          }
        });
        if (val === 'edit') {
          if (arr.length === 1) {
            if(this.authority.length !==0){
            for (let i = 0; i < this.authority.length; i++) {
                if(this.userName === this.authority[i].value){
                  this.taskFlag = false;
                    this.targetFlag = false;
                    this.directorIncomeFlag = false;
                    this.directorCostFlag = false;
                    this.directorDateFlag = false;
                }
              }
            }
            this.setTable(arr[0]);
             this.dictDialogVisible = true;
          } else {
            this.$notify({ title: this.$t('tips.fail'), message: this.$t('specialApplication.maintenance.pleaseSelectOne'), type: 'warning' }); // 失败 请选择一条记录
          }
        } else if (val === 'application') {
          if (this.selectionList[0].projectNo && this.selectionList[0].projectNo !== '') {
            this.$notify({ title: this.$t('tips.fail'), message: this.$t('specialApplication.maintenance.applyWarning'), type: 'warning' }); // 失败 该信息已有专编，无法再次申请
          } else {
            if (arr.length === 1) {
              this.$router.push({
                path: '/demandManager/specialApplication',
                query: { demandId: arr[0].id }
              });
            } else {
              this.$notify({
                title: this.$t('tips.fail'), // 失败
                message: this.$t('specialApplication.maintenance.pleaseSelectOne'), // 请选择一条记录
                type: 'warning'
              });
            }
          }
        }
      },
      setTable(val) {
        this.setBg('');
        this.dialogForm = {
          id: val.id,
          buId: val.buId,
          country: val.country,
          bg: val.bg,
          bu: val.bu,
          clientType: val.clientType,
          territory: val.territory,
          client: val.client,
          clientName: val.clientName,
          bdNo: val.bdNo,
          bdOrder: val.bdOrder,
          bdName: val.bdName,
          contactWindow: val.contactWindow,
          decisionMaker: val.decisionMaker,
          sales: val.sales,
          salesId: val.salesId,
          presales: val.presales,
          presalesId: val.presalesId,
          pm: val.pm,
          pmId: val.pmId,
          startDate: val.startDate,
          endDate: val.endDate,
          proposalDate: val.proposalDate,
          targetQuarterDate: val.targetQuarterDate,
          targetQuarter: val.targetQuarter,
          targetMonth: val.targetMonth,
          forecastMonth: val.forecastMonth,
          estimatedBudget: val.estimatedBudget,
          estimatedCost: val.estimatedCost,
          status: val.status,
          actionsSales: val.actionsSales,
          actionsPresales: val.actionsPresales,
          isFinish: val.isFinish,
          projectNo: val.projectNo,
          latelyDailySales: val.latelyDailySales,
          latelyDailyPresales: val.latelyDailyPresales,
          outerStartMeetingDateIs: val.outerStartMeetingDateIs,
          bidBeforeMeetingDate: val.bidBeforeMeetingDate,
          innerStartMeetingDate: val.innerStartMeetingDate,
          outerStartMeetingDate: val.outerStartMeetingDate,
          estimatedCostThis: val.estimatedCostThis,
          estimatedRevenueThis: val.estimatedRevenueThis,
          task: val.task,
          targetDate: val.targetDate,
          directorIncome: val.directorIncome,
          directorCost: val.directorCost,
          directorDate: val.directorDate
        };
        this.pm = val.pm
        this.sales = val.sales
        this.presales = val.presales
        this.client = val.client
      },
      resetForm(formName) {
        this.dictDialogVisible = false;
        this.dialogForm = {};
        this.setBgList = [];
        this.setBuList = [];
        this.$refs[formName].resetFields();
        window.sessionStorage.setItem('maintenanceDialogQuery', '');
        
      },
      // 排序
      sortDate(column) {
        // this.formatter.sortByKey(this.list, column.prop, column.order)
        // 如果不是金额排序，则请求接口
        if (column.order === 'ascending') {
          this.listQuery.order = 'asc';
        } else if (column.order === 'descending') {
          this.listQuery.order = 'desc';
        }
        // clientTypeName
        if (column.prop === 'clientTypeName') {
          this.listQuery.orderBy = 'clientType';
        } else if (column.prop === 'contactWindowF') {
          this.listQuery.orderBy = 'contactWindow';
        } else if (column.prop === 'decisionMakerF') {
          this.listQuery.orderBy = 'decisionMaker';
        } else if (column.prop === 'isFinishValue') {
          this.listQuery.orderBy = 'isFinish';
        } else {
          this.listQuery.orderBy = column.prop;
        }
        this.getList();
      },
      init() {
        // 判断跳转到新增客户之后再次进入该页面
        const maintenanceDialogQuery = window.sessionStorage.getItem(
          'maintenanceDialogQuery'
        );
        if (maintenanceDialogQuery) {
          const info = JSON.parse(maintenanceDialogQuery);
          // 如果是其他用户，则清空数据
          if (info.user === this.$store.getters.info.id) {
            this.dialogForm = info.form
            this.dictDialogVisible = info.status
            this.sales = info.sales
            this.presales = info.presales
            this.client = info.client
          } else {
            window.sessionStorage.setItem('maintenanceDialogQuery', '');
          }
        }
      },
      dialogClose() {
        this.dictDialogVisible = false
        window.sessionStorage.setItem('maintenanceDialogQuery', '');
      },
      goCustom() {
        this.$router.push({ path: '/baseManager/customer' })
        window.sessionStorage.setItem('maintenanceDialogQuery', JSON.stringify({
          form: this.dialogForm,
          status: this.dictDialogVisible,
          user: this.$store.getters.info.id,
          sales: this.sales,
          presales: this.presales,
          client: this.client
        }));
      }
    },
    verify() {
      if (this.dialogForm.startDate && this.dialogForm.endDate) {
        const startTime = this.dialogForm.startDate.split('T')[0];
        const endTime = this.dialogForm.endDate.split('T')[0];
        const formatStartTime = new Date(startTime);
        const formatEndTime = new Date(endTime);
        if (formatStartTime > formatEndTime) {
          return 'startDate必须小于endDate'
        }
      }
      // if (this.dialogForm.status &&
      //   (this.dialogForm.status === '8_Close' ||
      //     this.dialogForm.status === 'No Bid' ||
      //     this.dialogForm.status === 'Customer didn\'t pursue' ||
      //     this.dialogForm.status === 'Lost' ||
      //     this.dialogForm.status === 'Pending')
      // ) {
      //   if (!this.dialogForm.endDate) {
      //     return '请输入End Date'
      //   }
      // }
      // 设置winOdds
      // this.dialogForm.winOdds =
      // this.listMapAll.demandStatus[this.dialogForm.status] || '';
      // 判断targetMonth和targetQuarter时间不能小于当前时间
      // const data = new Date()
      // const year = data.getFullYear()
      // const month = data.getMonth() + 1
      // if (this.dialogForm.targetMonth) {
      //   const targetMonth = this.dialogForm.targetMonth.split('-')
      //   if (targetMonth[0] * 1 < year) {
      //     return 'Target Month时间不能小于当前时间'
      //   }
      //   if (targetMonth[0] * 1 === year && targetMonth[1] * 1 < month) {
      //     return 'Target Month时间不能小于当前时间'
      //   }
      // }
      // if (this.dialogForm.targetQuarter) {
      //   const targetQuarter = this.dialogForm.targetQuarter.split('"Q')
      //   if (targetQuarter[0] * 1 < year) {
      //     return 'Target Quarter时间不能小于当前时间'
      //   }
      //   if (targetQuarter[0] * 1 === year && targetQuarter[1] * 3 < month) {
      //     return 'Target Quarter时间不能小于当前时间'
      //   }
      // }
      // if (this.dialogForm.winOdds && Number(this.dialogForm.winOdds) >= 70) {
      //   if (!this.dialogForm.targetMonth) {
      //     return 'winOdds>=70%时,targetMonth必填'
      //   }
      // }
      // if (this.dialogForm.status !== '1_Notice' && this.dialogForm.status !== '2_Identify' &&
      //   this.dialogForm.status !== '3_Validate' && this.dialogForm.status !== '4_Qualify'
      // ) {
      //   if (!this.dialogForm.estimatedCost) {
      //     return 'Status>=5_Proposed时，Estimated cost必填'
      //   }
      // }
      // if (!this.dialogForm.estimatedBudget && !this.dialogForm.targetQuarter) {
      //   if (this.dialogForm.status !== '1_Notice' && this.dialogForm.status !== '2_Identify') {
      //     return '请重新检查Estimated Budget，Target Quarter栏位'
      //   }
      // }
      // if ((!this.dialogForm.estimatedBudget && this.dialogForm.targetQuarter) ||
      //   (this.dialogForm.estimatedBudget && !this.dialogForm.targetQuarter)
      // ) {
      //   if (this.dialogForm.status !== '3_Validate') {
      //     return '请重新检查Estimated Budget，Target Quarter栏位'
      //   }
      // }
      // if (this.dialogForm.estimatedBudget && this.dialogForm.targetQuarter) {
      //   if (this.dialogForm.status === '1_Notice' || this.dialogForm.status === '2_Identify' ||
      //     this.dialogForm.status === '3_Validate'
      //   ) {
      //     return '请重新检查Estimated Budget，Target Quarter栏位'
      //   }
      // }
    },
    beforeDestroy() {
      this.reset();
      window.sessionStorage.setItem('searchMaintenance', JSON.stringify(this.listQuery))
    }
  };
</script>

<style lang="scss">
 .box1{
    height: 36px;
    line-height: 36px;
    text-align: center;
    border-radius: 4px;
    color: #333;
    cursor:text;
    padding:0 15px;
  }
.app-container.maintenance {
  .apply-query{
      .el-col-4{
        height: 69px;
      }
  }

  .item_tips {
    width: 200%;
    color: #f56c6c;
    font-size: 12px;
    line-height: 1;
    padding-top: 4px;
    position: absolute;
    top: 100%;
    left: 0;
    cursor: pointer;
    z-index: 9999
  }

  .check_div {
    height: 36px;
    width: 210px;
    line-height: 36px;
    background-color: rgb(255, 255, 255);
    border-radius: 4px;
    border: 1px solid rgb(220, 223, 230);
    box-sizing: border-box;
    display: block;
    outline: 0px;
    padding: 0px 30px !important;
    display: none;
  }

  .yt-table:hover {
    cursor: pointer;
  }

  .no_error /deep/ .el-form-item__error {
    display: none;
  }

  /deep/ .icon_question {
    cursor: pointer;
  }

  .box{
    height: 36px;
    line-height: 36px;
    text-align: left;
    border-radius: 4px;
    color: #333;
    cursor:text;
    padding:0 15px;
  }
  .box:empty:before{
    content: attr(placeholder);
    color: #c0c4cc;
    font-size: 12px;
  }
  /deep/ .el-textarea__inner{
    min-height: 36px !important;
    line-height: 2;
  }
}
</style>
